package com.example.demo.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.common.util.Base64Util;
import com.example.demo.common.util.DESUtil;
import com.example.demo.common.util.HttpClientUtil;
import com.example.demo.common.util.ResultVO;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.logging.SimpleFormatter;


@RestController
@RequestMapping("/demo")
public class DemoController<sendPlatForData> {

    /**
     * 加密秘钥
     */
    private static final String PLATFORM_NAME = "薪保抚州产业园";//朝歌测试
    private static final String PASS_WORD = "QxTTE4Tu";//朝歌测试
    private static final String PALTFORM = "KA2105250005";//朝歌测试

//    private static final String POST_URL = "http://127.0.0.1:8082/sync/api/syncdata";
    private static final String POST_URL = "https://rule.test.ihuike.net:8082/sync/api/syncdata";//测试环境
//    private static final String POST_URL = "https://rule.beta.ihuike.net/sync/api/syncdata";//预发环境
//    private static final String POST_URL = "http://121.199.172.140:8082/sync/api/syncdata";//联调环境

    //    private static final String SELF_POST_URL = "http://127.0.0.1:8082/sync/api/appliSelfAddress";//获取服务者的个体工商户编号
    private static final String SELF_POST_URL = "http://rule.test.ihuike.net:8082/sync/api/appliSelfAddress";
//    private static final String SELF_POST_URL = "http://121.199.172.140:8082/sync/api/appliSelfAddress";

    public static void main(String[] args) {

        /*======灵工数据上传，下拉接口开始======*/
//        //发送平台信息
//        sendPlatForData();
//        //发送企业信息
//        sendBusinessData();//待补充数据库信息
//        sendServerData();
//        //个体户信息接口
//        sendSelfBusiness();
        //任务信息接口
//        sendTaskData();
        //结算信息接口
        sendSetTementData();
//        //发票信息接口
//        sendBillData();
        //个体户普票拉取信息接口
//        selectSelfBusinessData();
        //个体户办理接口
//        selectServerData();
        /*=======灵工数据上传，下拉接口结束=====*/


        /*======其他工具接口开始======*/
        //申请个体工商户经营地址
//        appliSelfNo();
    }

    private static void appliSelfNo() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("platformCode", "KA2106010130");
        jsonObject.put("sevicerNo", "SNO248407576759373824");
//        jsonObject.put("commentId", "13026194071");
        String reqStr = JSON.toJSONString(jsonObject);
        System.out.println(reqStr);
        String objStr = HttpClientUtil.post(reqStr, SELF_POST_URL);
        JSONObject obj = JSON.parseObject(objStr);
        if (obj.getInteger("code") == 0) {
            System.out.println("请求成功");
            String selfAddress = obj.getString("result");
            System.out.println(selfAddress);
        } else {
            System.out.println("请求失败");
            String msg = obj.getString("msg");
            System.out.println(msg);
        }
    }

    public static void selectServerData() {
        List<Map<String, Object>> list = Arrays.asList(findServerData());
        sendMsg(list, "H1009");
    }

    public static void selectSelfBusinessData() {
        List<Map<String, Object>> list = Arrays.asList(selfBusinessData());
        sendMsg(list, "H1008");
    }

    public static void sendBillData() {
        List<Map<String, Object>> list = Arrays.asList(billData());
        sendMsg(list, "H1007");
    }

    public static void sendSetTementData() {
        List<Map<String, Object>> list = Arrays.asList(settementData());
        sendMsg(list, "H1006");
    }

    public static void sendTaskData() {
        List<Map<String, Object>> list = Arrays.asList(taskData());
        sendMsg(list, "H1005");
    }

    public static void sendSelfBusiness() {
        List<Map<String, Object>> list = Arrays.asList(selfBusiness());
        sendMsg(list, "H1004");
    }

    public static void sendServerData() {
        List<Map<String, Object>> list = Arrays.asList(serverData());
        sendMsg(list, "H1003");
    }

    /**
     * 发送企业信息
     *
     * @param
     * @return
     */
    public static void sendBusinessData() {
        List<Map<String, Object>> list = Arrays.asList(businessData());
        sendMsg(list, "H1002");
    }

    public static void sendPlatForData() {
        List<Map<String, Object>> list = Arrays.asList(platForData());//3（报文体放入list中，最多传5条）
        sendMsg(list, "H1001");
    }

    public static void sendMsg(List list, String reqCode) {
        JSONObject object = setHeadMsg(reqCode);
        JSONObject objectList = new JSONObject();
        objectList.put("LIST", list);
        object.put("BODY", objectList);
//        String jsonString = JSON.toJSONString(object);
        String jsonString = "{\"SERIALNO\":\"263786086400\",\"REQCODE\":\"H1002\",\"REQSRC\":\"H\",\"PLATFORMCODE\":\"KA2107150012\",\"BODY\":{\"LIST\":[{\"SOCIALCREDITCODE\":\"91120222MA06C0HB6N\",\"OPEN_TIME\":\"2018-05-08 00:00:00\",\"REGISTERUNIT\":\"1\",\"INDUSTYCODE\":\"4\",\"RATE\":\"0.00\",\"LOGO\":{\"DATA\":\"/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkz\\r\\nODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2Nj\\r\\nY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wAARCAS1BrcDASIA\\r\\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\\r\\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\\r\\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\\r\\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\\r\\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAt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d26e547d40778cddcfc6d983ec96.png\"},\"BUSINESSTYPE\":\"2\",\"END_TIME\":\"2021-09-13 22:02:32\",\"BUSINESSADDRESS\":\"天津市武清区汽车产业园云景道1号汽车大厦603室-19（集中办公区）\",\"LEGALPHONE\":\"15556900569\",\"OPERATIONSTATUS\":\"1\",\"BUSINESSNAME\":\"龙1测试企业\",\"BUSINESSNO\":\"1437416406253182976\",\"LICENSE\":{\"DATA\":\"/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkz\\r\\nODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2Nj\\r\\nY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wAARCAS1BrcDASIA\\r\\nAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA\\r\\nAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3\\r\\nODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm\\r\\np6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA\\r\\nAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx\\r\\nBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK\\r\\nU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3\\r\\nuLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDv6KKK\\r\\nACiiigAooooAKKa67sfMRg54p1ABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFAB\\r\\nRRRQAUUUUAFFFFABRRRQAUUUUAFFFMQOGcuwIJ+UAYwMf45oAfRRRQAUUUUAFFFFABRRRQAUUUUA\\r\\nFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAU\\r\\nUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRR\\r\\nRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFFABRRRQAUUUUAFFFF\\r\\nABRRRQAUUUUA\",\"FILENAME\":\"1.jpg\"}}]},\"PLATFORMNAME\":\"众薪科技\",\"BATCHNO\":\"1437465265618997248\",\"REQDATE\":\"2021-09-14 01:16:40\"}";
        System.out.println("加密前的请求数据" + "------" + jsonString);
        String encrypt = DESUtil.encrypt(PASS_WORD, jsonString);
//        System.out.println("加密后的请求数据"+"------"+encrypt);
//        String encrypt = "CiiFkiuKCe8TCnQeEYuWOum+f0JGLdG2TglbhJ1p4K4iufwoKvI57WwAatRg8B9BpVOrHhVgmWyTIUsUBq5nyyyO76gWkzv/4Hb+iCtpcufXLZqno0T2LVa6XLL2Bh8QH3rQnl29L5dG4PhwbyWBpmcj+fKnWDlKP4CTjrTOczTsKvvwW/56kM/88sGOr86pv+EeIth+SQNI7tDTTHi/uRXPAPy3jRGHWvUcqdy9YlVrIcqcZNkoQL6mTOlplpjsNaNJSJdDIGO6/t3xcYxT5rCl7N02XQiQDfcQLnRcEqkoBSvrqR8HG3AVmiy2sBjN0x+QP447cUHl0nlyQgMjG4qywVZOXtvEJw/vAS3DbcS8TmUdZtJbXCHTsBSyBB8ZCLU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Lbk0P+7ny5r4MIu3S7a3A51OBQiV1MScvI0CSneG3yAtoV6Msx7kx91GbH2H70d/mz1yqeopubPvqPAvSS3oNN2w8x9anjmtd1KFlhZXbowPyPeXEJ2o+pxmNWWlb4x5H4uIU+Ki17PvWC8S71y3pselWqyfbJRWvOvqC4W86mclogPfWgoNn8wEoGeu7hmL5PTJhmXyybAPFohSFJCuqjNJsqHBYJeRpuI/weUMDW0ncJrLuX/CubKW6rtaZ6kiRN0mGQYweJhW+MXaLOg==";
        HttpPost httpPost = httpPost(POST_URL, encrypt, reqCode);
        String send = send(httpPost);
        System.out.println(send);
        JSONObject jsonObject = JSON.parseObject(send);
        String result = (String) jsonObject.get("result");
        String decrypt = DESUtil.decrypt(PASS_WORD, result);
        System.out.println("解密后的响应数据" + "------" + decrypt);
        if ("H1009".equals(reqCode) && !StringUtils.isEmpty(decrypt)) {
//            List<Map<String, Object>> rd = (List<Map<String, Object>>) JSON.parseObject(decrypt);
            JSONArray rd = JSON.parseArray(decrypt);
            Map<String, Object> stringObjectMap = (Map<String, Object>) rd.get(0);
            Map<String, String> licenseMap = (Map<String, String>) stringObjectMap.get("LICENSE");
            String data = licenseMap.get("DATA");
            String fileName = licenseMap.get("FILENAME");
            Base64Util.decode(data, fileName + ".jpg", "D:\\crt_file\\image");

            Map<String, String> enFileMap = (Map<String, String>) stringObjectMap.get("ENFILE");
            if (!CollectionUtils.isEmpty(enFileMap)) {
                String enFileData = enFileMap.get("DATA");
                String enFileName = enFileMap.get("FILENAME");
                Base64Util.decode(enFileData, enFileName, "D:\\crt_file\\image");
            }


        } else if ("H1008".equals(reqCode) && !StringUtils.isEmpty(decrypt)) {
            JSONArray rd = JSON.parseArray(decrypt);
            Map<String, Object> stringObjectMap = (Map<String, Object>) rd.get(0);
            Object tasknum = stringObjectMap.get("TASKNUM");
            if (!Objects.isNull(tasknum)) {
                Long num = Long.valueOf(tasknum.toString());
            }
            Object isUploadBill = stringObjectMap.get("ISUPLOADBILL");
            if (!Objects.isNull(isUploadBill)) {
                Byte is = Byte.valueOf(isUploadBill.toString());
            }
            Map<String, String> licenseMap = (Map<String, String>) stringObjectMap.get("INVOICE");
            String data = licenseMap.get("DATA");
            String fileName = licenseMap.get("FILENAME");
            Base64Util.decode(data, fileName + ".jpg", "D:\\crt_file\\image");
        }
    }

    /**
     * 设置报文头
     */
    private final static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public static JSONObject setHeadMsg(String reqCode) {
        JSONObject object = new JSONObject();
        //获取body字符串
        object.put("PLATFORMCODE", PALTFORM);
        object.put("PLATFORMNAME", PLATFORM_NAME);
        object.put("REQDATE", formatter.format(new Date()));
        object.put("REQCODE", reqCode);
        object.put("REQSRC", "H");
        object.put("SERIALNO", "34624352348");
        object.put("BATCHNO", "3");
        return object;
    }


    public static String send(HttpPost post) {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        CloseableHttpResponse response = null;
        try {
            response = httpClient.execute(post, HttpClientContext.create());
            return EntityUtils.toString(response.getEntity());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (response != null) {
                try {
                    response.close();
                } catch (Exception e) {
                    e.getMessage();
                }
            }
        }
        return null;
    }

    public static HttpPost httpPost(String url, String body, String reqCode) {
        HttpPost post = new HttpPost(url);
        try {
            post.setHeader("PLATFORMCODE", PALTFORM);
            post.setHeader("REQCODE", reqCode);
            post.setHeader("SERIALNO", "1");
            post.setHeader("BATCHNO", "23");
            MultipartEntityBuilder builder = MultipartEntityBuilder.create();
            ContentType strContent = ContentType.create("text/plain", Charset.forName("UTF-8"));
            builder.addTextBody("data", body, strContent);
            HttpEntity parameterEntity = builder.build();
            post.setEntity(parameterEntity);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return post;
    }

    public static Map<String, Object> businessData() {
        //文件样例
        File license = new File("src/main/resources/1.png");
        File legalf = new File("src/main/resources/2.png");
        File legalb = new File("src/main/resources/3.png");
        File linkf = new File("src/main/resources/4.png");
        File linkb = new File("src/main/resources/5.png");
        File logo = new File("src/main/resources/111111111111111111111111111111111111111111111111111111111111.png");
        File agreement = new File("src/main/resources/e139d26e547d40778cddcfc6d983ec96.txt");
        Map<String, Object> map = new HashMap<>();
        map.put("BUSINESSNO", "123456");
        map.put("BUSINESSNAME", "好汉帮公司");
        map.put("BUSINESSTYPE", "2");
        map.put("BUSINESSTYPEMSG", "有限责任公司");
        map.put("INDUSTYCODE", "4");
        map.put("INDUSTYCODEMSG", "物流运输");
        map.put("LEGALNAME", "路人一");
        map.put("LEGALPHONE", "18600006666");
        map.put("LEGALIDCARD", "110110199001013814");
        map.put("SOCIALCREDITCODE", "110110110110110110");
        map.put("OPEN_TIME", "2020-01-01 00:00:00");
        map.put("END_TIME", "2025-01-01 00:00:00");
        map.put("BUSINESSADDRESS", "辽宁省葫芦岛市");
        map.put("OPERATIONSTATUS", "1");
        map.put("OPERATIONSTATUSMSG", "存续");
        map.put("REGISTERUNIT", "北京市海淀区市场监督管理局");
        map.put("BUSINESSSCOPE", "餐饮管理及配送服务、普通货物运输、货物代购服务、车辆代驾服务、车辆信息咨询服务。");
        map.put("ISDISABLE", "1");
        map.put("RATE", "10.50");
        map.put("LINKMANNAME", "1");
        map.put("LINkMANIDCARD", "1");
//        map.put("LINKIDCARDFROND","1");
//        map.put("LINKIDCARDBACK","1");
//        map.put("LEGALIDCARDFROND","1");
//        map.put("LEGALIDCARDBACK","1");
        //使用 营业执照照片
        HashMap<String, String> licenseMap = new HashMap<>();
        licenseMap.put("FILENAME", license.getName());
        licenseMap.put("DATA", Base64Util.encode(license));
        map.put("LICENSE", licenseMap);
        //法人正
//        HashMap<String, String> legalfMap = new HashMap<>();
//        legalfMap.put("FILENAME", legalf.getName());
//        legalfMap.put("DATA", Base64Util.encode(legalf));
//        map.put("LEGALIDCARDFROND", legalfMap);
        //法人反
//        HashMap<String, String> legalbMap = new HashMap<>();
//        legalbMap.put("FILENAME", legalb.getName());
//        legalbMap.put("DATA", Base64Util.encode(legalb));
//        map.put("LEGALIDCARDBACK", legalbMap);
        //联系人正
//        HashMap<String, String> linkfMap = new HashMap<>();
//        linkfMap.put("FILENAME", linkf.getName());
//        linkfMap.put("DATA", Base64Util.encode(linkf));
//        map.put("LINKIDCARDFROND", linkfMap);
        //联系人反
//        HashMap<String, String> linkbMap = new HashMap<>();
//        linkbMap.put("FILENAME", linkb.getName());
//        linkbMap.put("DATA", Base64Util.encode(linkb));
//        map.put("LINKIDCARDBACK", linkbMap);
        //使用 合同/协议文件
        HashMap<String, String> agreementMap = new HashMap<>();
        agreementMap.put("FILENAME", agreement.getName());
        agreementMap.put("DATA", Base64Util.encode(agreement));
        map.put("AGREEMENT", agreementMap);
        //logo
        HashMap<String, String> logoMap = new HashMap<>();
        logoMap.put("FILENAME", logo.getName());
        logoMap.put("DATA", Base64Util.encode(logo));
        map.put("LOGO", logoMap);
        return map;
    }


    /**
     * 3.2.1.	灵工平台信息接口
     */
    public static Map<String, Object> platForData() {
        //文件样例
        File license = new File("src/main/resources/1.png");
        File logo = new File("src/main/resources/2.png");
        File agreement = new File("src/main/resources/e139d26e547d40778cddcfc6d983ec96.txt");
        Map<String, Object> map = new HashMap<>();
        map.put("PLATFORMNAME", "朝歌科技城");
        map.put("ENTERPRISENAME", "朝歌互联");
        map.put("LEGALNAME", "张大海");
        map.put("LEGALPHONE", "18622223333");
        map.put("LEGALIDCARD", "110110199001013814");
        map.put("BUSINESSTYPE", "2");
        map.put("BUSINESSTYPEMSG", "有限责任公司");
        map.put("INDUSTYCODE", "1");
        map.put("INDUSTYCODEMSG", "广告");
        map.put("OPERATIONSTATUS", "1");
        map.put("OPERATIONSTATUSMSG", "存续");
        map.put("SOCIALCREDITCODE", "123456asdfghjkl");
        map.put("OPEN_TIME", "2020-01-01 00:00:00");
        map.put("END_TIME", "2025-01-01 00:00:00");
        map.put("REGISTERUNIT", "北京市海淀区市场监督管理局");
        map.put("LINKMANNAME", "李富贵");
        map.put("LINKMANPHONE", "18239395309");
        map.put("BANKNO", "62214819870411");
        map.put("BANKNAME", "招商银行");
        map.put("BUSINESSADDRESS", "北京市朝阳门大街1号");
        map.put("BUSINESSSCOPE", "餐饮管理及配送服务、普通货物运输、货物代购服务、" +
                "车辆代驾服务、车辆信息咨询服务。");
        //使用 营业执照照片
        HashMap<String, String> licenseMap = new HashMap<>();
        licenseMap.put("FILENAME", license.getName());
        licenseMap.put("DATA", Base64Util.encode(license));
        map.put("LICENSE", licenseMap);
        //使用 合同/协议文件
        HashMap<String, String> agreementMap = new HashMap<>();
        agreementMap.put("FILENAME", agreement.getName());
        agreementMap.put("DATA", Base64Util.encode(agreement));
        map.put("AGREEMENT", agreementMap);
        HashMap<String, String> logoMap = new HashMap<>();
        logoMap.put("FILENAME", logo.getName());
        logoMap.put("DATA", Base64Util.encode(agreement));
        map.put("LOGO", logoMap);
        return map;
    }

    public static Map<String, Object> serverData() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String, Object> map = new HashMap<>();
        map.put("SEVICERNO", "SNO884878847302469888");
        map.put("SEVICERNAME", "张森森");
        map.put("SEX", "1");
        map.put("IDCARD", "410928198704185196");
        map.put("PHONE", "18239395309");
        map.put("ADDRESS", "北京市大兴区");
        map.put("SELFADDRESS", "江西省抚州市临川区抚北工业园才都工业区临川新一代信息技术科创产业园C7栋3-034");
        map.put("ISBUSINESS", "1");
        File idCardFrond = new File("src/main/resources/1.png");
        File idCardBack = new File("src/main/resources/2.png");
        File t1 = new File("src/main/resources/平台协议-测试模板.pdf");
        File t2 = new File("src/main/resources/自由职业者委托协议测试模板.pdf");
        File t3 = new File("src/main/resources/意愿视频测试模板.mp4");
        HashMap<String, String> idCardFrondMap = new HashMap<>();
        idCardFrondMap.put("FILENAME", idCardFrond.getName());
        idCardFrondMap.put("DATA", Base64Util.encode(idCardFrond));
        map.put("IDCARDFROND", idCardFrondMap);
        HashMap<String, String> idCardBackMap = new HashMap<>();
        idCardBackMap.put("FILENAME", idCardBack.getName());
        idCardBackMap.put("DATA", Base64Util.encode(idCardBack));
        map.put("IDCARDBACK", idCardBackMap);
        HashMap<String, String> t1map = new HashMap<>();
        t1map.put("FILENAME", t1.getName());
        t1map.put("DATA", Base64Util.encode(t1));
        map.put("PLATFORMAGREEMENT", t1map);
        HashMap<String, String> t2map = new HashMap<>();
        t2map.put("FILENAME", t2.getName());
        t2map.put("DATA", Base64Util.encode(t2));
        map.put("AUTHAGREEMENT", t2map);
        HashMap<String, String> t3map = new HashMap<>();
        t3map.put("FILENAME", t3.getName());
        t3map.put("DATA", Base64Util.encode(t3));
        map.put("WILLVIDE", t3map);

//        map.put("ACCOUNT_TYPE","2");
//        map.put("REALNAME","张森森");
//        map.put("BANKNAME","建设银行");
//        map.put("BANKNO","6227000130060672100");
//        map.put("BANKPHONE","18233132379");
        map.put("IDCARDBEGINDATE", sdf.format(new Date()));
        map.put("IDCARDENDDATE", sdf.format(new Date()));
        return map;
    }

    /**
     * 废弃
     *
     * @return
     */
    public static Map<String, Object> selfBusiness() {
        //文件样例
        File license = new File("src/main/resources/1.png");
        File agreement = new File("src/main/resources/e139d26e547d40778cddcfc6d983ec96.txt");
        Map<String, Object> map = new HashMap<>();
        map.put("SELFBUSINESSNO", "12312312");
        map.put("SEVICERNO", "123123123");
        //使用 营业执照照片
        HashMap<String, String> licenseMap = new HashMap<>();
        licenseMap.put("FILENAME", license.getName());
        licenseMap.put("DATA", Base64Util.encode(license));
        map.put("LICENSE", licenseMap);
        map.put("BUSINESSNAME", "BBBBBB");
        map.put("SOCIALCREDITCODE", "12312312313");
        map.put("BUSINESSTYPE", "1");
        map.put("BUSINESSTYPEMSG", "1");
        map.put("INDUSTYCODE", "1");
        map.put("INDUSTYCODEMSG", "1");
        map.put("OPEN_TIME", "2020-01-01 00:00:00");
        map.put("END_TIME", "2025-01-01 00:00:00");
        map.put("REGISTERUNIT", "北京市大兴区管理局");
        map.put("OPERATIONSTATUS", "1");
        map.put("OPERATIONSTATUSMSG", "1");
        map.put("BUSINESSADDRESS", "北京市丰台区");
        map.put("BUSINESSSCOPE", "广告等等");
        return map;
    }

    public static Map<String, Object> taskData() {
        Map<String, Object> map = new HashMap<>();
        map.put("TASKNO", "CP251284554034319360");
        map.put("BUSINESSNO", "123456");
        map.put("TASKNAME", "zsstask");
        map.put("TASKPAYMENT", "213324.26");
        map.put("TASKADDRESS", "北京市朝阳区");
        map.put("TASKDESCRIPTION", "20人力");
        map.put("AUDITSTATUS", "1");
        map.put("NEEDPEOPLENUM", "4");
        map.put("INDUSTYCODE", "1");
        map.put("INDUSTYCODEMSG", "1");
        map.put("RELEASEDATE", "2021-04-05 11:51:55");
        map.put("ENDDATE", "2021-05-05 11:51:55");
        map.put("CREATETIME", "2020-01-01 00:00:00");
        map.put("TASKSTATUS", "2");
        Map<String, Object> objectMap = new HashMap<>();
        objectMap.put("TASKDETAILNO", "56789");
        objectMap.put("SELFBUSINESSID", "KG2107150034");
        objectMap.put("TAKESTATUS", "1");
        objectMap.put("ISCOMPLETE", "1");
        objectMap.put("BONUS", "50000");
        objectMap.put("FINE", "10000");
//        objectMap.put("SUBFEE", "111");//======================
//        objectMap.put("RECEIVABLEFEE", "22222");//==============
        objectMap.put("TAKETIME", "2021-04-05 11:51:55");
        objectMap.put("COMPLETETIME", "2021-05-05 11:51:55");
        List<Map> list = new ArrayList<>();
        list.add(objectMap);
        map.put("TASKDETAIL", list);
        return map;
    }

    public static Map<String, Object> settementData() {
        Map<String, Object> map = new HashMap<>();
        map.put("SETTLEMENTNO", "666");
        map.put("BUSINESSNO", "123456");
        map.put("CREATETIME", "2021-05-17 12:12:12");
        map.put("STARTTIME", "2021-05-18 12:12:12");
        map.put("ENDTIME", "2021-06-17 12:12:12");
        map.put("AMOUNT", "2000");
        map.put("TAX", "100");
        map.put("FEE", "200");
        map.put("FEE_RATE", "2.00");
        map.put("SETTLEMENTAMOUNT", "2300");
        map.put("SETTLEMENTSTATUS", "1");
        map.put("PAYMENTSTATUTS", "1");
        map.put("RECEIVEDBUSINESSNUM", "2");
        map.put("FINISHEDBUSINESSNUM", "2");
        Map<String, Object> objectMap = new HashMap<>();
        objectMap.put("SETTLEMENTDETAILNO", "111");
        objectMap.put("SELFBUSINESSNO", "KG2107150034");
        objectMap.put("SUBFEE", "3333");
        objectMap.put("ACCOUNT_TYPE", "2");
        objectMap.put("RECEIVECARDNO", "22222222222222222");
        objectMap.put("RECEIVEBANK", "33333333333333333");
        Map<String, Object> objectMap2 = new HashMap<>();
        objectMap2.put("TASKNO", "CP251284554034319360");
        List<Map> arrayList2 = new ArrayList();

        arrayList2.add(objectMap2);
        objectMap.put("SETTLEMENTTASKDETAIL", arrayList2);
        List<Map> arrayList = new ArrayList();
        arrayList.add(objectMap);
        map.put("SETTLEMENTDETAIL", arrayList);

        File paymentDetailUrl = new File("src/main/resources/1.png");
        File paymentReceiptUrl = new File("src/main/resources/2.png");
        File platformPaymentDetailUrl = new File("src/main/resources/3.png");
        File platformPaymentReceiptUrl = new File("src/main/resources/4.png");

        map.put("PAYMENTDETAIL", fileNode(paymentDetailUrl));
        map.put("PAYMENTRECEIPT", fileNode(paymentReceiptUrl));
        map.put("PLATFORMPAYMENTDETAIL", fileNode(platformPaymentDetailUrl));
        map.put("PLATFORMPAYMENTRECEIPT", fileNode(platformPaymentReceiptUrl));

        return map;
    }

    public static Map<String, String> fileNode(File file) {
        HashMap<String, String> node = new HashMap<>();
        node.put("FILENAME", file.getName());
        node.put("DATA", Base64Util.encode(file));
        return  node;
    }

    public static Map<String, Object> billData() {
        Map<String, Object> map = new HashMap<>();
        map.put("BILLNO", "123456789");
        map.put("BILLNUMBER", "123123123");
        map.put("BILLCODE", "123412341234");
        map.put("INVOICETAXNUMBER", "2222220001100");
        map.put("BILLTYPE", "2");
        map.put("BILLAMOUNT", "5000");
        map.put("BILLTAX", "2000");
        map.put("BILLEDBODYNO", "211220112210");
        map.put("BILLDRAWER", "14002200100001");
        map.put("BILLTIME", "2020-01-01 00:00:00");
        Map<String, String> map1 = new HashMap<>();
        map1.put("SETTLEMENTNO", "1111");
//        Map<String,String> map2 = new HashMap<>();
//        map2.put("SETTLEMENTNO","1234445552255");
        List<Map<String, String>> list = Arrays.asList(map1);
        map.put("SETTLEMENTNOLIST", list);
        return map;
    }

    public static Map<String, Object> selfBusinessData() {
        Map<String, Object> map = new HashMap<>();
        map.put("SELFBUSINESSNO", "KG2107230038");
        map.put("STARTTIME", "2020-09-09 09:09:09");
        return map;
    }

    public static Map<String, Object> findServerData() {
        Map<String, Object> map = new HashMap<>();
        map.put("SEVICERNO", "SNO884878847302469666");
        return map;
    }


}
